Note: This tutorial assumes you have already created your own URDF file or that you are working with the existing PR2 URDF file. |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Start using the KDL parser
Description: This tutorial teaches you how to create a KDL Tree from a URDF fileTutorial Level: BEGINNER
Contents
Building the KDL parser
$ rosdep install kdl_parser
This will install all the external dependencies for the kdl_parser. To build the package, run:
$ rosmake kdl_parser
Using in your code
First, add the KDL parser as a dependency to your package.xml (in ROS fuerte or earlier it's manifest.xml) file:
<package> ... <build_depend package="kdl_parser" /> ... <run_depend package="kdl_parser" /> ... </package>
To start using the KDL parser in your C++ code, include the following file:
Now there are different ways to proceed. You can construct a KDL tree from a urdf in various forms:
From a file
- To create the PR2 URDF file, run the following command:
$ rosrun xacro xacro.py `rospack find pr2_description`/robots/pr2.urdf.xacro > pr2.urdf
From the parameter server
From an xml element
1 KDL::Tree my_tree; 2 TiXmlDocument xml_doc; 3 xml_doc.Parse(xml_string.c_str()); 4 xml_root = xml_doc.FirstChildElement("robot"); 5 if (!xml_root){ 6 ROS_ERROR("Failed to get robot from xml document"); 7 return false; 8 } 9 if (!kdl_parser::treeFromXml(xml_root, my_tree)){ 10 ROS_ERROR("Failed to construct kdl tree"); 11 return false; 12 }
From a URDF model
For more details, take a look at the API documentation.